package com.hzy.fivepalace.wx.controller.api;

import com.hzy.fivepalace.db.vo.wx.WxConfirmOrderQueryVo;
import com.hzy.fivepalace.wx.annotation.LoginUser;
import com.hzy.fivepalace.wx.controller.base.BaseController;
import com.hzy.fivepalace.wx.service.WxBuyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/wx/buy")
@Validated
@Api(tags = "统一购买服务")
public class WxBuyController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(WxBuyController.class);

    @Resource
    private WxBuyService wxBuyService;


    /**
     * 商品确认订单，查询一些关键信息返回
     *
     * @param userId
     * @param query
     * @return
     */
    @PostMapping("/confirmOrder")
    @ApiOperation(value = "商品确认订单")
    public Object confirmOrder(@LoginUser @ApiParam(hidden = true) Integer userId, @RequestBody WxConfirmOrderQueryVo query) {
        return wxBuyService.confirmOrder(userId, query,false);
    }

    /**
     * 提交订单
     *
     * @param userId
     * @param query
     * @return
     */
    @PostMapping("/submitOrder")
    @ApiOperation(value = "提交订单")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class})
    public Object submitOrder(@LoginUser @ApiParam(hidden = true) Integer userId, @RequestBody WxConfirmOrderQueryVo query) {
        return wxBuyService.submitOrder(userId, query);
    }
}
